package com.iflyteck;

import com.iflyteck.boot.InitServerBoot;
import com.iflyteck.handler.ZookeeperHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ServerBootStrap implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(ServerBootStrap.class,args);
    }

    @Autowired
    private ZookeeperHandler zookeeperHandler;

    @Override
    public void run(String... args) throws Exception {
        // 服务器启动的端口通过启动参数传递
        int port = Integer.parseInt(args[0]);
        InitServerBoot.startServer(port);
        zookeeperHandler.registerToZookeeper(port);
    }
}
